#include "stdafx.h"
#include "objectrun.h"
#include "objectloader.h"
#include "rot.h"
#include "plugins.h"

CObjectRunImpl::CObjectRunImpl()
{
    Reset();
}

CObjectRunImpl::~CObjectRunImpl(void)
{
    logi("CObjectRunImpl::~CObjectRunImpl");
}
HRESULT CObjectRunImpl::SetMainRun(IBase* pBase)
{
    rc_error(pBase != NULL, E_FAIL);
    m_pIMainRun.dispose();

    return pBase->QueryInterface(IID_IMainRun, (void**)&m_pIMainRun);
}

HRESULT CObjectRunImpl::SetClsid(REFCLSID clsid)
{
    HRESULT hr = S_OK;

    m_strObjectClsid = clsid;

    return hr;
}
CLSID CObjectRunImpl::GetClsid()
{
    return m_strObjectClsid;
}
HRESULT CObjectRunImpl::LoadConf(const SafeStringPtr* code)
{
    HRESULT hr = S_OK;

    rc_error(code != NULL, OBJECT_RUN_RET_PARAMERR);
    rc_error(code->len != 0, OBJECT_RUN_RET_PARAMERR);
    rc_error(code->ptr != NULL, OBJECT_RUN_RET_PARAMERR);

    m_Plugins.Clear();

    hr = LoadRunConf(code->ptr, code->len);
    rc_error(hr == S_OK, OBJECT_RUN_RET_MEMERR);

    m_strRegisterCode.clear();
    m_strRegisterCode.append(code->ptr);

    hr = LoadBasePlugin();
    rc_error(hr == S_OK, OBJECT_RUN_RET_ROTERR);

    hr = LoadContainers();
    rc_error(hr == S_OK, OBJECT_RUN_RET_COMPERR);

    return hr;
}
LPCSTR CObjectRunImpl::GetConf()
{
    return m_strRegisterCode.c_str();
}
HRESULT CObjectRunImpl::Register(SafeStringConstPtr name, UINT type, UINT version)
{
    rc_error(m_pILibManager != NULL, E_FAIL);
    return m_pILibManager->Register(name, type, version);
}
HRESULT CObjectRunImpl::UnRegister(SafeStringConstPtr name, UINT type, UINT version)
{
    rc_error(m_pILibManager != NULL, E_FAIL);
    return m_pILibManager->UnRegister(name, type, version);
}
HRESULT CObjectRunImpl::Registers(UINT type, UINT version)
{
    rc_error(m_pILibManager != NULL, E_FAIL);
    return m_pILibManager->Registers(type, version);
}
HRESULT CObjectRunImpl::UnRegisters(UINT type, UINT version)
{
    rc_error(m_pILibManager != NULL, E_FAIL);
    return m_pILibManager->UnRegisters(type, version);
}
HRESULT CObjectRunImpl::SetPath(const SafePStringPtr* path)
{
    rc_error(path != NULL, OBJECT_RUN_RET_PARAMERR);
    rc_error(path->len != 0, OBJECT_RUN_RET_PARAMERR);
    rc_error(path->ptr != NULL, OBJECT_RUN_RET_PARAMERR);

    m_strRunPath.clear();
    m_strRunPath.append(path->ptr);

    m_strContainer.clear();
    TCHAR szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00};
    get_dynamicname(_T("container"), szPluginName, DYNAMIC_NAME_LEN);
    m_strContainer = m_strRunPath;
    m_strContainer.append(path_slash);
    m_strContainer.append(szPluginName);

    return S_OK;
}
LPSTRING CObjectRunImpl::GetPath()
{
    return m_strRunPath.c_str();
}
HRESULT CObjectRunImpl::Load()
{
    HRESULT hr = S_OK;

    this->Registers(11, 11);

    return hr;
}
HRESULT CObjectRunImpl::Init(_pid_t pid, basic_tchar* argv[], int argc)
{
    HRESULT hr = S_OK;

    hr = LoadPlugins();
    rc_error(hr == S_OK, OBJECT_RUN_RET_CLSIDERR);

    hr = SetRunArgc(argc, argv);
    rc_error(hr == S_OK, OBJECT_RUN_RET_CLSIDERR);

    return hr;
}

HRESULT CObjectRunImpl::Start(UINT type)
{
    m_type = type;
    return DoPluginsStartFunc(m_type);
}

HRESULT CObjectRunImpl::Stop(UINT type, UINT exit)
{
    return DoPluginsStopFunc(type, exit);
}

UINT CObjectRunImpl::Run(UINT type)
{
    return DoPluginsRun(type);
}

HRESULT CObjectRunImpl::Exit(UINT exit)
{
    ExitPtr pExit;
    m_pIRot->GetObject(m_RunPlugin, IID_IExit, (IBase**)&pExit);
    rc_error(pExit.m_p != INULL, OBJECT_RUN_RET_SUCCESS);
    return pExit->OnExit(exit);
}
HRESULT CObjectRunImpl::Uninit()
{
    rc_error(m_pIRot.m_p != INULL, E_FAIL);
    rc_error(m_pILibManager.m_p != INULL, E_NOINTERFACE);

    UninitAllPlugins();
    DestroyAllRotPlugin();
    m_pILibManager->Free();

    Reset();

    m_pIRot.dispose();
    m_pILibManager.dispose();
    m_pIMainRun.dispose();

    return S_OK;
}

HRESULT CObjectRunImpl::Clear()
{
    return Reset();
}

HRESULT CObjectRunImpl::GetRotPlugin(IBase** pBase)
{
    rc_error(m_pIRot.m_p != INULL, E_NOINTERFACE);
    return m_pIRot->QueryInterface(IID_IRot, (void**)pBase);
}

HRESULT CObjectRunImpl::GetMsgPlugin(IBase** pBase)
{
    return this->QueryInterface(IID_IMsgPlugin, (void**)pBase);
}

HRESULT CObjectRunImpl::GetLoaderPlugin(IBase** pBase)
{
    rc_error(m_pIRot.m_p != INULL, E_NOINTERFACE);
    return m_pIRot->GetObject(CLSID_CLoader, IID_ICreator, (IBase**)pBase);
}

HRESULT CObjectRunImpl::GetMainRunPlugin(IBase** pBase)
{
    rc_error(m_pIMainRun.m_p != INULL, E_NOINTERFACE);
    return m_pIMainRun->QueryInterface(IID_IMainRun, (void**)pBase);
}

HRESULT CObjectRunImpl::AddObject(REFCLSID clsid, LPCSTR progid, IBase* pBase, ULONG index, LPCSTR container, UINT type)
{
    HRESULT hr = S_OK;

    _lComPtr<IBase> pObject;
    hr = pBase->QueryInterface(IID_IBase, (void**)&pObject);
    rc_error(pObject.m_p != NULL, E_FAIL);
    rc_error(hr == S_OK, E_FAIL);

    PluginPtr pPlugin;
    hr = pBase->QueryInterface(IID_IPlugin, (void**)&pPlugin);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pPlugin.m_p != NULL, E_FAIL);

    if (type & STD_INIT)
        hr = pPlugin->Init(m_pIRot, m_pIMainRun);

    if (type & STD_MSG)
        hr = RunMsgPlugin_Start(pObject);

    if (type & STD_START)
        hr = RunPlugin_Start(pObject, 0);

    if (type & STD_ROT)
        hr = m_pIRot->Register(clsid, progid, pBase, index);

    if (type & STD_VEC)
        m_PluginsClsid.push_back(Com_Plugin(clsid, index, container));

    return S_OK;
}

CLSID CObjectRunImpl::GetRunPluginCLSID()
{
    return m_RunPlugin;
}

ULONG CObjectRunImpl::GetRunPluginsCount()
{
    return m_PluginsClsid.size();
}
ULONG CObjectRunImpl::GetRunIndex(ULONG index)
{
    rc_error(((index >= 0) && (index < m_PluginsClsid.size())), 0);
    return m_PluginsClsid[index].GetIndex();
}

UINT CObjectRunImpl::GetExitCode()
{
    return m_exitcode;
}

UINT CObjectRunImpl::GetArgc()
{
    return m_argc;
}
LPSTRING CObjectRunImpl::GetIndexArgc(UINT index)
{
    rc_error(((index >= 0) && (index < m_argc)), NULL);
    return m_argv[index];
}
UINT CObjectRunImpl::GetStartType()
{
    return m_type;
}
_pid_t CObjectRunImpl::get_instance()
{
    return m_pid;
}
HRESULT CObjectRunImpl::OnMsgStart()
{
    return S_OK;
}
HRESULT CObjectRunImpl::OnMsgStop()
{
    return S_OK;
}
HRESULT CObjectRunImpl::OnMsgSend(CLSID sn, CLSID tn, UINT msg, IBase* inmsg, IBase** outmsg)
{
    return SendMessage(sn, tn, msg, inmsg, outmsg);
}
HRESULT CObjectRunImpl::OnMsgRecv(CLSID sn, CLSID tn, UINT msg, IBase* inmsg, IBase** outmsg)
{
    return S_OK;
}
ULONG CObjectRunImpl::GetRoute()
{
    return 0;
}
ULONG CObjectRunImpl::GetSub()
{
    return 0;
}
HRESULT CObjectRunImpl::Set(ULONG ad)
{
    return S_OK;
}

HRESULT CObjectRunImpl::SetRunArgc(int argc, basic_tchar* argv[])
{
    m_argc = argc;
    m_argv = argv;
    return S_OK;
}

HRESULT CObjectRunImpl::LoadRunConf(LPCSTR buf, ULONG len)
{
    return m_Plugins.LoadMemory(buf, len);
}

HRESULT CObjectRunImpl::LoadBasePlugin()
{
    HRESULT hr = S_OK;

    _lComPtr<IBase> pIBase;

    CRotImpl* pRot = NULL;
    pRot = ALLOC_NEW CRotImpl();
    rc_error(pRot != NULL, E_FAIL);

    hr = pRot->QueryInterface(IID_IRot, (void**)&m_pIRot);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);

    CObjectLoader* pObjectLoader = NULL;
    pObjectLoader = ALLOC_NEW CObjectLoader();
    rc_error(pObjectLoader != NULL, E_FAIL);

    pObjectLoader->QueryInterface(IID_IBase, (void**)&pIBase);
    rc_error(hr == S_OK, E_FAIL);

    pObjectLoader->QueryInterface(IID_ILibManager, (void**)&m_pILibManager);
    rc_error(hr == S_OK, E_FAIL);

    hr = m_pIRot->Register(CLSID_CLoader, "loader.V1", pIBase, 0);
    rc_error(hr == S_OK, E_FAIL);

    pIBase.dispose();

    this->QueryInterface(IID_IBase, (void**)&pIBase);
    rc_error(hr == S_OK, E_FAIL);

    hr = m_pIRot->Register(CLSID_CObjectRun, "objectrun.V1", pIBase, 0);
    rc_error(hr == S_OK, E_FAIL);

    return hr;
}

HRESULT CObjectRunImpl::LoadPlugins()
{
    DWORD dwCount = 0;
    m_PluginsClsid.clear();
    dwCount = m_Plugins.LoadClsidAll(m_PluginsClsid);
    rc_error(dwCount > 0, E_FAIL);

    UINT uloop = 0;

    for (uloop = 0; uloop < dwCount; uloop++) {
        CreatePlugin(m_PluginsClsid[uloop].GetClsid(), uloop);
    }
    return S_OK;
}

HRESULT CObjectRunImpl::LoadContainers()
{
    ComponentPlugin PluginsComponents;
    PluginsComponents.clear();
    PluginsComponents = m_Plugins.LoadCompents();

    rc_error(PluginsComponents.size() > 0, E_FAIL);

    ComponentPluginIterator it = PluginsComponents.begin();

    while (it != PluginsComponents.end()) {
        HRESULT hr = LoadContainer(it->first.c_str());

        basic_tchar path[MAX_PATH + 1] = {0x00};

        m_pILibManager->Get(it->first.c_str(), path, MAX_PATH);

        if (S_FAILED(hr)) {
            loge("RegisterContainer ==>:%s", it->first.c_str());
        }
        it++;
    }
    return S_OK;
}

HRESULT CObjectRunImpl::LoadContainer(LPCSTR name)
{
    rc_error(name != NULL, E_FAIL);
    path_string path = ContainerPath(name);
    return m_pILibManager->Load(path.c_str(), name);
}
HRESULT CObjectRunImpl::FreeContainer(LPCSTR name)
{
    rc_error(name != NULL, E_FAIL);
    return m_pILibManager->Remove(name);
}

HRESULT CObjectRunImpl::CreatePlugin(REFCLSID clsid, UINT index)
{
    char guid[GUIDStringLength] = {0x00};
    GUIDToString(&clsid, guid);

    _lComPtr<IBase> pBase;
    HRESULT hr = CreateRotPlugin(clsid, (IBase**)&pBase, index);

    if (S_FAILED(hr)) {
        logi("create_plugin_error==>guid==>%s", guid);
        return hr;
    }

    PluginPtr pPlugin;
    hr = pBase->QueryInterface(IID_IPlugin, (void**)&pPlugin);
    rc_error(hr == S_OK, E_FAIL);

    if (pPlugin) {
        hr = pPlugin->Init(m_pIRot, m_pIMainRun);

        if (S_FAILED(hr)) {
            logi("init_plugin_error==>guid==>%s", guid);
            pPlugin->Uninit();
            DestroyRotPlugin(clsid);
        }
    }
    return hr;
}

HRESULT CObjectRunImpl::UninitAllPlugins()
{
    rc_error(m_PluginsClsid.size() > 0, S_OK);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);

    ULONG uSize = 0;
    uSize = m_PluginsClsid.size();

    ULONG uloop = 0;

    for (uloop = 0; uloop < uSize; uloop++) {
        HRESULT hr = S_OK;

        ULONG index = uSize - uloop - 1;
        rc_error_continue(((index >= 0) && (index < uSize)));

        _lComPtr<IBase> pUnknown;
        hr = m_pIRot->GetObject(m_PluginsClsid[index].GetClsid(), IID_IBase, (IBase**)&pUnknown);
        rc_error_continue(hr == S_OK);

        PluginPtr pPlugin;
        hr = pUnknown->QueryInterface(IID_IPlugin, (void**)&pPlugin);
        rc_error_continue(hr == S_OK);

        if (pPlugin) {
            pPlugin->Uninit();
        } else {
            char guid[GUIDStringLength] = {0x00};

            CLSID id = m_PluginsClsid[index].GetClsid();

            GUIDToString(&id, guid);
            logi("uinit_plugin_error==>guid:%s", guid);
        }
    }

    return S_OK;
}

HRESULT CObjectRunImpl::CreateRotPlugin(REFCLSID clsid, IBase** plugin, UINT index)
{
    rc_error(clsid != IID_INULL, E_FAIL);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);

    HRESULT hr = S_OK;
    hr = m_pIRot->CreateInstance(clsid, NULL, IID_IBase, (void**)plugin);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(*plugin != NULL, E_FAIL);

    //???
    LPCSTR progid = m_pIRot->ProgIDFromCLSID(clsid);
    //???

    return m_pIRot->Register(clsid, progid, *plugin, index);
}

HRESULT CObjectRunImpl::DestroyAllRotPlugin()
{
    rc_error(m_PluginsClsid.size() > 0, S_OK);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);

    ULONG Size = 0;
    Size = m_PluginsClsid.size();

    ULONG uloop = 0;
    for (uloop = 0; uloop < Size; uloop++) {
        ULONG index = Size - uloop - 1;
        rc_error_continue(((index >= 0) && (index < Size)));
        DestroyRotPlugin(m_PluginsClsid[index].GetClsid());
    }

    DestroyRotPlugin(CLSID_CObjectRun);

    DestroyRotPlugin(CLSID_CLoader);

    return m_pIRot->RevokeAll();
}

HRESULT CObjectRunImpl::DestroyRotPlugin(REFCLSID clsid)
{
    rc_error(clsid != IID_INULL, E_FAIL);
    rc_error(m_pIRot.m_p != NULL, E_FAIL);
    return m_pIRot->Revoke(clsid);
}

HRESULT CObjectRunImpl::SendMessage(CLSID sn, CLSID tn, UINT msg, IBase* inmsg, IBase** outmsg)
{
    HRESULT hr = S_OK;
    rc_error(m_PluginsClsid.size() > 0, S_OK);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);
    ULONG uloop = 0;

    for (uloop = 0; uloop < m_PluginsClsid.size(); uloop++) {
        rc_error((uloop >= 0 && uloop < m_PluginsClsid.size()), E_FAIL);

        _lComPtr<IBase> pUnknown;
        hr = m_pIRot->GetObject(m_PluginsClsid[uloop].GetClsid(), IID_IBase, (IBase**)&pUnknown);
        rc_error_continue(hr == S_OK);

        if (tn == m_PluginsClsid[uloop].GetClsid()) {
            hr = RunMsgPlugin_Recv(pUnknown, sn, tn, msg, inmsg, outmsg);
            goto msg_end;
        } else if (tn == IID_INULL) {
            hr = RunMsgPlugin_Recv(pUnknown, sn, tn, msg, inmsg, outmsg);
        }
    }
    return E_FAIL;
msg_end:
    return hr;
}

UINT CObjectRunImpl::DoPluginsRun(UINT uType)
{
    HRESULT hr = S_OK;
    UINT uExit = OBJECT_RUN_RET_SUCCESS;

    // Do not care about the start stop function running results
    hr = DoPluginsStartFunc(uType);

    uExit = GetIExitCode(m_RunPlugin);

    logi("exit_code==>%u", uExit);

    hr = DoPluginsStopFunc(uType, uExit);

    return uExit;
}

HRESULT CObjectRunImpl::DoPluginsStartFunc(UINT uType)
{
    HRESULT hr = S_OK;

    ULONG uSize = m_PluginsClsid.size();
    rc_error(uSize > 0, S_OK);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);
    ULONG uloop = 0;

    for (uloop = 0; uloop < uSize; uloop++) {
        rc_error((uloop >= 0 && uloop < m_PluginsClsid.size()), E_FAIL);

        _lComPtr<IBase> pUnknown;
        hr = m_pIRot->GetObject(m_PluginsClsid[uloop].GetClsid(), IID_IBase, (IBase**)&pUnknown);
        rc_error_continue(hr == S_OK);

        char guid[GUIDStringLength] = {0x00};

        CLSID id = m_PluginsClsid[uloop].GetClsid();

        GUIDToString(&id, guid);

        m_RunPlugin = m_PluginsClsid[uloop].GetClsid();

        RunPlugin_Start(pUnknown, uType);
    }

    m_exitcode = GetIExitCode(m_RunPlugin);

    return hr;
}

HRESULT CObjectRunImpl::DoPluginsStopFunc(UINT uType, UINT uExit)
{
    HRESULT hr = S_OK;
    ULONG uSize = m_PluginsClsid.size();
    rc_error(uSize > 0, S_OK);
    rc_error(m_pIRot.m_p != INULL, E_FAIL);
    ULONG uloop = 0;

    for (uloop = 0; uloop < uSize; uloop++) {
        rc_error((uloop >= 0 && uloop < m_PluginsClsid.size()), E_FAIL);

        unsigned long index = uSize - uloop - 1;
        rc_error_continue(((index >= 0) && (index < m_PluginsClsid.size())));

        _lComPtr<IBase> pUnknown;
        hr = m_pIRot->GetObject(m_PluginsClsid[index].GetClsid(), IID_IBase, (IBase**)&pUnknown);
        rc_error_continue(hr == S_OK);

        char guid[GUIDStringLength] = {0x00};

        CLSID id = m_PluginsClsid[uloop].GetClsid();

        GUIDToString(&id, guid);

        RunPlugin_Stop(pUnknown, uExit);
    }
    return hr;
}

UINT CObjectRunImpl::GetIExitCode(CLSID iid)
{
    ExitPtr pExit;
    m_pIRot->GetObject(iid, IID_IExit, (IBase**)&pExit);
    rc_error(pExit.m_p != INULL, OBJECT_RUN_RET_SUCCESS);
    return pExit->GetExitCode();
}
HRESULT CObjectRunImpl::RunPlugin_Start(BaseConstPtr pBase, UINT type)
{
    RunMsgPlugin_Start(pBase);
    return RunStdPlugin_Start(pBase, type);
}
HRESULT CObjectRunImpl::RunPlugin_Stop(BaseConstPtr pBase, UINT exit)
{
    RunMsgPlugin_Stop(pBase);
    return RunStdPlugin_Stop(pBase, exit);
}

HRESULT CObjectRunImpl::RunStdPlugin_Start(BaseConstPtr pBase, UINT type)
{
    HRESULT hr = S_OK;
    PluginRunPtr pPluginRun;
    hr = pBase->QueryInterface(IID_IPluginRun, (void**)&pPluginRun);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pPluginRun.m_p != NULL, E_FAIL);
    return pPluginRun->Start(m_pid, type);
}

HRESULT CObjectRunImpl::RunStdPlugin_Stop(BaseConstPtr pBase, UINT exit)
{
    HRESULT hr = S_OK;
    PluginRunPtr pPluginRun;
    hr = pBase->QueryInterface(IID_IPluginRun, (void**)&pPluginRun);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pPluginRun.m_p != NULL, E_FAIL);
    return pPluginRun->Stop(exit);
}

HRESULT CObjectRunImpl::RunMsgPlugin_Start(BaseConstPtr pBase)
{
    HRESULT hr = S_OK;
    MsgPluginPtr pMsgPlugin;
    hr = pBase->QueryInterface(IID_IMsgPlugin, (void**)&pMsgPlugin);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pMsgPlugin.m_p != NULL, E_FAIL);
    return pMsgPlugin->OnMsgStart();
}

HRESULT CObjectRunImpl::RunMsgPlugin_Stop(BaseConstPtr pBase)
{
    HRESULT hr = S_OK;
    MsgPluginPtr pMsgPlugin;
    hr = pBase->QueryInterface(IID_IMsgPlugin, (void**)&pMsgPlugin);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pMsgPlugin.m_p != NULL, E_FAIL);
    return pMsgPlugin->OnMsgStop();
}
HRESULT CObjectRunImpl::RunMsgPlugin_Recv(BaseConstPtr pBase, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg)
{
    HRESULT hr = S_OK;
    MsgPluginPtr pMsgPlugin;
    hr = pBase->QueryInterface(IID_IMsgPlugin, (void**)&pMsgPlugin);
    rc_error(hr == S_OK, E_FAIL);
    rc_error(pMsgPlugin.m_p != NULL, E_FAIL);
    return pMsgPlugin->OnMsgRecv(sn, tn, msg, inmsg, outmsg);
}
HRESULT CObjectRunImpl::Reset()
{
    m_strRunPath.clear();
    m_PluginsClsid.clear();
    m_Plugins.Clear();

    m_argc = 0;
    m_argv = NULL;
    m_RunPlugin = IID_INULL;
    m_pIRot.dispose();
    m_pILibManager.dispose();

    m_type = 0;
    m_pid = pid_null;
    m_exitcode = OBJECT_RUN_RET_SUCCESS;

    return S_OK;
}

path_string CObjectRunImpl::ContainerPath(LPCSTR ComponentName)
{
    path_string stringpath;
    stringpath.clear();
    stringpath.append(m_strRunPath);
    stringpath.append(path_slash);

#if (TARGET_OS == OS_WIN)

    SafePtr<basic_tchar*, ChartoUcs2Struct> pBuf;
    pBuf = char_to_wchar(ComponentName, s_strlen(ComponentName));
    basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00};
    get_dynamicname(pBuf, szPluginName, DYNAMIC_NAME_LEN);

#elif (TARGET_OS == OS_POSIX)

    basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00};
    get_dynamicname(ComponentName, szPluginName, DYNAMIC_NAME_LEN);

#elif (TARGET_OS == OS_MACH)

    basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00};
    get_dynamicname(ComponentName, szPluginName, DYNAMIC_NAME_LEN);

#elif (TARGET_OS == OS_UNIX)

    basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00};
    get_dynamicname(ComponentName, szPluginName, DYNAMIC_NAME_LEN);

#endif

    stringpath += szPluginName;
    return stringpath;
}
